package com.ofr.controller.common;

import com.ofr.ejb.dao.IssueDao;
import com.ofr.ejb.dao.UserDao;
import com.ofr.ejb.entities.Issue;
import com.ofr.ejb.entities.User;


import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.inject.Named;
import javax.servlet.http.HttpSession;
import java.util.List;

import com.ofr.util.Constants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * Created with IntelliJ IDEA.
 * User: imon
 * Date: 2/18/13
 * Time: 11:19 AM
 * To change this template use File | Settings | File Templates.
 */

@Named
@RequestScoped
public class IndexController implements Constants{

    protected final Log log = LogFactory.getLog(getClass());


    private List<Issue> issueList;
    private String searchKeyword;

    public String getSearchKeyword() {
        return searchKeyword;
    }

    public List<Issue> getIssueList() {
        if(searchKeyword == null){
            issueList = issueDao.getRecentIssue();
        }
        return issueList;
    }

    public void setIssueList(List<Issue> issueList) {
        this.issueList = issueList;
    }

    public void setSearchKeyword(String searchKeyword) {
        this.searchKeyword = searchKeyword;
    }

    @EJB
    private IssueDao issueDao;


    @PostConstruct
    public void init() {
        System.out.println("in init method ");
    }

    public void searchIssue() {
        issueList = issueDao.searchActiveIssueByTitle(searchKeyword);
    }

    public String donate() {
        return DONATE;
    }
}